<div data-test="transaction_log" class="tile tile-muted">
  <% decoded_result = decode(@log, @transaction) %>
  <%= case decoded_result do %>
    <% {:error, :contract_not_verified, _candidates} -> %>
      <div class="alert alert-info">
      <%= gettext "To see accurate decoded input data, the contract must be verified." %>
      <%= case @log do %>
        <% %{address_hash: %Explorer.Chain.Hash{} = address_hash} -> %>
          <% path = address_verify_contract_path(@conn, :new, address_hash) %>
          <%= gettext "Verify the contract " %><a href="<%= path %>"><%= gettext "here" %></a>
        <% _ -> %>
          <%= nil %>
      <% end %>
      </div>
    <% _ -> %>
      <%= nil %>
  <% end %>

  <% implementation_names = Implementation.names(@log.address) %>
  <% implementation_name =
        if Enum.empty?(implementation_names) do
          nil
        else
          implementation_names |> Enum.at(0)
        end
  %>

  <dl class="row">
    <dt class="col-lg-2"> <%= gettext "Address" %> </dt>
    <dd class="col-lg-10">
      <h3 class="logs-hash">
        <% name = implementation_name || primary_name(@log.address)%>
        <%= link(
            (if name, do: name <> " | "<> to_string(@log.address), else: @log.address),
            to: address_path(@conn, :show, @log.address),
            "data-test": "log_address_link",
            "data-address-hash": @log.address
          ) %>
      </h3>
    </dd>
      <%= case decoded_result do %>
        <% {:error, :could_not_decode} -> %>
          <dt class="col-lg-2"><%= gettext "Decoded" %></dt>
          <dd class="col-lg-10">
          <div class="alert alert-danger">
            <%= gettext "Failed to decode log data." %>
          </div>
        <% {:error, :no_matching_function} -> %>
          <%= nil %>
        <% {:ok, method_id, text, mapping} -> %>
          <dt class="col-lg-2"><%= gettext "Decoded" %></dt>
          <dd class="col-lg-10">
          <table summary="Transaction Info" class="table thead-light table-bordered transaction-input-table">
            <tr>
              <td>Method Id</td>
              <td colspan="3"><code>0x<%= method_id %></code></td>
            </tr>
            <tr>
              <td>Call</td>
              <td colspan="3"><code><%= text %></code></td>
            </tr>
          </table>
          <%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
          <% {:error, :contract_not_verified, results} -> %>
            <%= for {:ok, method_id, text, mapping} <- results do %>
               <dt class="col-md-2"><%= gettext "Decoded" %></dt>
               <dd class="col-md-10">
               <table summary="Transaction Info" class="table thead-light table-bordered transaction-input-table">
                 <tr>
                   <td>Method Id</td>
                   <td colspan="3"><code>0x<%= method_id %></code></td>
                 </tr>
                 <tr>
                   <td>Call</td>
                   <td colspan="3"><code><%= text %></code></td>
                 </tr>
               </table>
               <%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
            <% end %>
          <% {:error, :contract_verified, results} -> %>
            <%= for {:ok, method_id, text, mapping} <- results do %>
               <dt class="col-md-2"><%= gettext "Decoded" %></dt>
               <dd class="col-md-10">
               <table summary="Transaction Info" class="table thead-light table-bordered transaction-input-table">
                 <tr>
                   <td>Method Id</td>
                   <td colspan="3"><code>0x<%= method_id %></code></td>
                 </tr>
                 <tr>
                   <td>Call</td>
                   <td colspan="3"><code><%= text %></code></td>
                 </tr>
               </table>
               <%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
            <% end %>
        <% _ -> %>
          <%= nil %>
      <% end %>

    <dt class="col-lg-2"><%= gettext "Topics" %></dt>
    <dd class="col-lg-10">
      <div class="raw-transaction-log-topics">
        <%= unless is_nil(@log.first_topic) do %>
          <div class="text-dark">
            <span class="text-dark">[0]</span>
            <%= @log.first_topic %>
          </div>
        <% end %>
        <%= unless is_nil(@log.second_topic) do %>
          <div class="text-dark">
            <span class="">[1] </span>
            <%= @log.second_topic %>
          </div>
        <% end %>
        <%= unless is_nil(@log.third_topic) do %>
          <div class="text-dark">
            <span>[2]</span>
            <%= @log.third_topic %>
          </div>
        <% end %>
        <%= unless is_nil(@log.fourth_topic) do %>
          <div class="text-dark">
            <span>[3]</span>
            <%= @log.fourth_topic %>
          </div>
        <% end %>
      </div>
    </dd>
    <dt class="col-lg-2">
      <%= gettext "Data" %>
    </dt>
    <dd class="col-lg-10">
      <%= unless is_nil(@log.data) do %>
        <div class="text-dark raw-transaction-log-data">
          <%= @log.data %>
        </div>
      <% end %>
    </dd>
    <dt class="col-md-2">
      <%= gettext "Log Index" %>
    </dt>
    <dd class="col-md-10">
      <div class="text-dark raw-transaction-log-index">
        <%= @log.index %>
      </div>
    </dd>
  </dl>
</div>
